package org.game.msgBuilder;

import org.apache.commons.lang3.tuple.Pair;
import org.game.db.bean.ComposeSummon;
import org.game.db.bean.Player;
import org.game.protobuf.s2c.S2CSummonMsg;

import java.util.List;
import java.util.Map;

/**
 * Created by fxf on 2017-12-23.
 */
public class SummonMsgBuilder {

    public static S2CSummonMsg.Summon buildSummonMsg(List<Pair> itemList) {
        S2CSummonMsg.Summon.Builder builder = S2CSummonMsg.Summon.newBuilder();
        itemList.forEach(pair-> builder.addItem(ShareMsgBuilder.createReward((int)pair.getLeft(),(int)pair.getRight())));
        return builder.build();
    }

    public static S2CSummonMsg.GetComposeInfo buildGetComposeInfo(Player player) {
        S2CSummonMsg.GetComposeInfo.Builder builder = S2CSummonMsg.GetComposeInfo.newBuilder();
        List<ComposeSummon> composeSummonList = player.getComposeSummonsFkPlayerId();
        composeSummonList.forEach(composeSummon -> builder.addComposeInfos(buildComposeSummonInfo(composeSummon)));
        return builder.build();
    }

    public static S2CSummonMsg.ComposeSummon buildComposeSummonMsg(ComposeSummon composeSummon){
        S2CSummonMsg.ComposeSummon.Builder builder = S2CSummonMsg.ComposeSummon.newBuilder();
        builder.setComposeInfo(buildComposeSummonInfo(composeSummon));
        return builder.build();
    }

    public static S2CSummonMsg.ComposeInfo buildComposeSummonInfo(ComposeSummon composeSummon) {
        S2CSummonMsg.ComposeInfo.Builder subBuilder = S2CSummonMsg.ComposeInfo.newBuilder();
        subBuilder.setCid(composeSummon.getCid());
        subBuilder.setFinishTime((int) (composeSummon.getFinishTime().getTime() / 1000));
        return subBuilder.build();
    }

    public static S2CSummonMsg.ComposeFinish buildComposeFinishMsg(Map<Integer,Integer> itemMap,int zPointType){
        S2CSummonMsg.ComposeFinish.Builder builder = S2CSummonMsg.ComposeFinish.newBuilder();
        itemMap.forEach((k,v)-> builder.addItem(ShareMsgBuilder.createReward(k,v)));
        builder.setZPointType(zPointType);
        return builder.build();
    }

    public static S2CSummonMsg.NoticeComposeFinish buildNoticeComposeFinishMsg(List<ComposeSummon> list){
        S2CSummonMsg.NoticeComposeFinish.Builder builder = S2CSummonMsg.NoticeComposeFinish.newBuilder();
        list.forEach(compose->{
            builder.addCid(compose.getCid());
        });
        return builder.build();
    }

//
}
